package lesson14;

import java.util.Scanner;

public class AuctionDemo {

	/*
	 * Create an auction. The auction can have N cars.
	 * The auction can have up to N cars for sale.
	 * The auction can have up to M participants to buy.
	 * The auction opens.
	 * Each participant can buy 1 or 2 cars.
	 * Each participant decides weather to buy a car by a random boolean value.
	 * Cars can be bought only once
	 * If no other cars are left in the auction, the remaining participants go home.
	 * After all participants have decided OR all cars are sold, the auction closes.
	 * If after all sales there are still cars left, the cars are scrapped.
	 * 
	 * Input: number of cars, number of participants.
	 * Output: 1:All participants that bought a car and the model of their cars.
	 *         2:All scrapped cars if any.
	 * 
	 */
	
	public static void main(String[] args) {
		
		//	int random = (int)Math.round(Math.random() + 1);
		//create auction
		Auction auction = new Auction();	
		Scanner s = new Scanner(System.in);
		System.out.println("Insert number of cars:");
		int numberOfCars = s.nextInt();
		auction.carsForSale = new Car[numberOfCars];
		System.out.println("Insert number of participants:");
		int numberOfParticipants = s.nextInt();
		auction.participants = new Person[numberOfParticipants];
		//fill cars in auction
		for(int i = 0; i < auction.carsForSale.length; i++)
		{
			auction.carsForSale[i] = new Car();
			auction.carsForSale[i].model = "Ferari"+i;
		}
		//fill participants in auction
		for(int i = 0; i < auction.participants.length; i++)
		{
			auction.participants[i] = new Person();
			auction.participants[i].initializeCarsCapacity();
			auction.participants[i].name = "Ivan"+i;
		}
		//open auction
		auction.open();
		auction.processSales();
		//close the auction
		auction.close();
		//list all participants that bought a car
				
		for(int j = 0; j < auction.carsForSale.length; j++)
		{
			if(auction.carsForSale[j].owner != null)//is bought
			{
				System.out.println("Buyer " + auction.carsForSale[j].owner.name + " bought " + auction.carsForSale[j].model);
				
			}
		}
		//list all cars for scrap
		for(int j = 0; j < auction.carsForSale.length; j++)
		{
			if(auction.carsForSale[j].owner == null)//is for scrap
			{
				System.out.println("Car for scrap - " + auction.carsForSale[j].model);
			}
		}
	}
}
